package cn.tedu.system.oa.user.controller;

import cn.tedu.system.oa.base.response.JsonResult;
import cn.tedu.system.oa.user.pojo.dto.UserLoginParam;
import cn.tedu.system.oa.user.pojo.dto.UserQuery;
import cn.tedu.system.oa.user.pojo.dto.UserSaveParam;
import cn.tedu.system.oa.user.pojo.vo.UserVO;
import cn.tedu.system.oa.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/oa/user/")
@Slf4j
@Api(tags = "01.用户模块")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("login")
    @ApiOperation("用户登录功能")
    public JsonResult userLogin(UserLoginParam userLoginParam){
        log.debug("用户登录:参数={}",userLoginParam);
        UserVO userVO = userService.userLogin(userLoginParam);
        return JsonResult.ok(userVO);
    }

    @GetMapping("select")
    @ApiOperation("用户列表展示功能")
    public JsonResult selectUser(UserQuery userQuery){
        log.debug("加载用户列表:参数={}",userQuery);
        List<UserVO> list = userService.selectUser(userQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    @ApiOperation("新增/修改用户信息功能")
    public JsonResult saveUser(UserSaveParam userSaveParam){
        log.debug("保存用户:参数={}",userSaveParam);
        userService.saveUser(userSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("reset/{userId}")
    @ApiOperation("重置密码功能")
    public JsonResult resetPwd(@PathVariable Integer userId){
        log.debug("重置密码:参数={}",userId);
        userService.resetPwd(userId);
        return JsonResult.ok();
    }

    @ApiOperation("删除用户功能")
    @PostMapping("delete/{userId}")
    public JsonResult deleteUser(@PathVariable Integer userId){
        log.debug("删除用户:参数={}",userId);
        userService.deleteUser(userId);
        return JsonResult.ok();
    }

    @ApiOperation("查询不是部门负责人的用户")
    @GetMapping("select/user/level")
    public JsonResult selectUserLevel(){
        List<UserVO> list = userService.selectUserLevel();
        log.debug("查询不是部门负责人的用户列表:{}",list);
        return JsonResult.ok(list);
    }
}
